<?php
/* Author: tbloc@cantho.gov.vn */
/* Created Date : 17-07-2014 10:10:51 */
class M_Chi_tiet_hoa_don{  
//Properties
private $CTHD_ID;
private $HD_ID;
private $HH_ID;
private $CTHD_SOLUONG;
private $CTHD_GHICHU;
//properties set get 
public function setCTHD_ID($CTHD_ID) 
{
	$this->CTHD_ID = $CTHD_ID;
}
public function getCTHD_ID()
{
	return $this->CTHD_ID;
}	        
public function setHD_ID($HD_ID) 
{
	$this->HD_ID = $HD_ID;
}
public function getHD_ID()
{
	return $this->HD_ID;
}	        
public function setHH_ID($HH_ID) 
{
	$this->HH_ID = $HH_ID;
}
public function getHH_ID()
{
	return $this->HH_ID;
}	        
public function setCTHD_SOLUONG($CTHD_SOLUONG) 
{
	$this->CTHD_SOLUONG = $CTHD_SOLUONG;
}
public function getCTHD_SOLUONG()
{
	return $this->CTHD_SOLUONG;
}	        
public function setCTHD_GHICHU($CTHD_GHICHU) 
{
	$this->CTHD_GHICHU = $CTHD_GHICHU;
}
public function getCTHD_GHICHU()
{
	return $this->CTHD_GHICHU;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi_tiet_hoa_don`(                        
			`CTHD_ID`, 
				`HD_ID`, 
				`HH_ID`, 
				`CTHD_SOLUONG`, 
				`CTHD_GHICHU` 
		)
	VALUES(
    		:CTHD_ID, 
	    		:HD_ID, 
	    		:HH_ID, 
	    		:CTHD_SOLUONG, 
	    		:CTHD_GHICHU 
	    );";
	$parameters = array(
			":CTHD_ID", 
				":HD_ID", 
				":HH_ID", 
				":CTHD_SOLUONG", 
				":CTHD_GHICHU" 
		);
    $values = array(  
            	$this->getCTHD_ID(), 
	            	$this->getHD_ID(), 
	            	$this->getHH_ID(), 
	            	$this->getCTHD_SOLUONG(), 
	            	$this->getCTHD_GHICHU()
	    );
    $types = array(
   
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                        PDO::PARAM_STR
                       );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setCTHD_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "update `chi_tiet_hoa_don`
	                set `is_active`=0
	                where `CTHD_ID` = :CTHD_ID;";
	        $parameters = array(":CTHD_ID");
	        $values = array($this->getCTHD_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi_tiet_hoa_don` SET 
			`CTHD_ID`=:CTHD_ID,
				`HD_ID`=:HD_ID,
				`HH_ID`=:HH_ID,
				`CTHD_SOLUONG`=:CTHD_SOLUONG,
				`CTHD_GHICHU`=:CTHD_GHICHU
			WHERE `CTHD_ID` = :CTHD_ID;";
	            $parameters = array(
	        	":CTHD_ID",
		        	":HD_ID",
		        	":HH_ID",
		        	":CTHD_SOLUONG",
		        	":CTHD_GHICHU"
		        );	
	$values = array(  
	        	$this->getCTHD_ID(),
        	        	$this->getHD_ID(),
        	        	$this->getHH_ID(),
        	        	$this->getCTHD_SOLUONG(),
        	                $this->getCTHD_GHICHU()      
        	);
    $types = array(
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_STR
                       );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`CTHD_ID`,
				`HD_ID`,
				`HH_ID`,
				`CTHD_SOLUONG`,
				`CTHD_GHICHU`
			FROM `chi_tiet_hoa_don` WHERE `CTHD_ID` = :CTHD_ID and `is_active`=1;";
	$parameters = array(":CTHD_ID");
	$values = array($this->getCTHD_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setCTHD_ID($row->CTHD_ID);
		$this->setHD_ID($row->HD_ID);
		$this->setHH_ID($row->HH_ID);
		$this->setCTHD_SOLUONG($row->CTHD_SOLUONG);
		$this->setCTHD_GHICHU($row->CTHD_GHICHU);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`CTHD_ID`,
				`HD_ID`,
				`HH_ID`,
				`CTHD_SOLUONG`,
				`CTHD_GHICHU`
			FROM `chi_tiet_hoa_don` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new chi_tiet_hoa_don();
    	 $obj->setCTHD_ID($row->CTHD_ID);
		 $obj->setHD_ID($row->HD_ID);
		 $obj->setHH_ID($row->HH_ID);
		 $obj->setCTHD_SOLUONG($row->CTHD_SOLUONG);
		 $obj->setCTHD_GHICHU($row->CTHD_GHICHU);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

